package com.hyz.login.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyz.login.model.Report;
import com.hyz.login.service.ReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 2022/11/24  何昱泽
 */
@Controller
public class ReportController {
    Logger logger = LoggerFactory.getLogger(ReportController.class);

    @Autowired
    private ReportService reportService;


    @RequestMapping("/page/caotake/selhuan")
    @ResponseBody
    public String findPage(String params,
                           @RequestParam(required = false,defaultValue = "1")Integer page,
                           @RequestParam(required = false,defaultValue = "5")Integer limit){
        IPage<Report> iPage = reportService.findPage(params, page, limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }

    @RequestMapping("/page/rep/findAll")
    @ResponseBody
    public String findPage(@RequestParam(required = false,defaultValue = "1")Integer page,
                           @RequestParam(required = false,defaultValue = "5")Integer limit){
        IPage<Report> iPage = reportService.findReg( page, limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }
}
